package com.example.demo.ai.model;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 面试会话状态类，用于管理面试过程中的会话信息
 */
public class SessionState {
    private final String sessionId;
    private final String resumeText;
    private final String position;
    private final LocalDateTime createdAt;
    private boolean active;
    private int questionCount;
    private List<HistoryEntry> history;

    public SessionState(String sessionId, String resumeText, String position) {
        this.sessionId = sessionId;
        this.resumeText = resumeText;
        this.position = position;
        this.createdAt = LocalDateTime.now();
        this.active = true;
        this.questionCount = 0;
        this.history = new ArrayList<>();
    }

    public String getSessionId() {
        return sessionId;
    }

    public String getResumeText() {
        return resumeText;
    }

    public String getPosition() {
        return position;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public int getQuestionCount() {
        return questionCount;
    }

    public void incrementQuestionCount() {
        this.questionCount++;
    }

    public List<HistoryEntry> getHistory() {
        return history;
    }

    public void addHistoryEntry(String role, String content) {
        history.add(new HistoryEntry(role, content));
    }

    /**
     * 判断是否应该结束面试
     * 默认当问题数量达到10个时结束面试
     */
    public boolean shouldEndInterview() {
        return questionCount >= 10;
    }

    /**
     * 历史记录条目类
     */
    public static class HistoryEntry {
        private final String role;
        private final String content;
        private final LocalDateTime timestamp;

        public HistoryEntry(String role, String content) {
            this.role = role;
            this.content = content;
            this.timestamp = LocalDateTime.now();
        }

        public String getRole() {
            return role;
        }

        public String getContent() {
            return content;
        }

        public LocalDateTime getTimestamp() {
            return timestamp;
        }
    }
}